package com.qf;

import com.qf.pojo.User;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamDemo1 {
    public static void main(String[] args) {

        List<String> names = new ArrayList<>();
        names.add("张三丰");
        names.add("张无忌");
        names.add("张翠三");
        names.add("赵敏");
        names.add("周芷若");
        names.add("小昭");

        //遍历names中名字为3个字的数据
        names
                .stream()
                .filter(str->str.length()==3)
                .forEach(System.out::println);

        //遍历姓张的和姓赵的名字
        names.stream().filter(str->str.startsWith("张") || str.startsWith("赵")).forEach(System.out::println);

        //将List<String> 变成 List<User>
//        Stream<String> stream = names.stream();
//        Stream<User> userStream = stream.map((str) -> new User(str));
//        List<User> userList = userStream.collect(Collectors.toList());

//        List<User> userList = names.stream().map(str -> new User(str)).collect(Collectors.toList());
        List<User> userList = names.stream().map(User::new).collect(Collectors.toList());

        System.out.println(userList);
    }
}
